﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Microsoft.AspNet.Identity;
using WebsiteClient.DB;
using WebsiteClient.Models;
using Microsoft.AspNet.Identity;
//using Server.Controller;
//using Server;

namespace WebsiteClient.Controllers
{
    [Authorize]
    public class EventController : Controller
    {
        private static EventDB eventDb = new EventDB();
        // GET: Event
        public ActionResult Index()
        {
            return View(eventDb.GetEventsById(User.Identity.GetUserId()));
        }


        // GET: Event/Details/5
        public ActionResult Details(int id)
        {
            return View();
        }

        // GET: Event/Create
        public ActionResult Create()
        {
            return View();
        }

        // POST: Event/Create
        [HttpPost]
        public ActionResult Create(EventViewModel model)
        {
            var eventCtrl = new ApiControllers.EventController();
            Event newEvent = new Event();
            newEvent.Title = model.Title;
            newEvent.Description = model.Description;
            newEvent.Date= model.Date;
            newEvent.Price = model.Price;
            newEvent.Address = model.Address;
            newEvent.ZipCode = model.Zipcode;
            newEvent.City = model.City;
            newEvent.Time = "00:00";
            newEvent.ApplicationUser_Id = User.Identity.GetUserId();
            eventCtrl.AddEvent(newEvent);

            if (eventDb.FindEventByTitle(newEvent.Title) != null)
            {
                return View();
            }
            else
            {
                return View("Error");
            }
            
        }

        // GET: Event/Edit/5
        public ActionResult Edit(int id)
        {
            return View();
        }

        // POST: Event/Edit/5
        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        // GET: Event/Delete/5
        public ActionResult Delete(int id)
        {
            return View();
        }

        // POST: Event/Delete/5
        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        public List<Event> GetEventsById(string id)
        {
            return eventDb.GetEventsById(id);
        }
    }
}
